// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <pollux/dwio/common/selective_struct_column_reader.h>

namespace kumo::pollux::dwio::common {
    class ColumnLoader : public VectorLoader {
    public:
        ColumnLoader(
            SelectiveStructColumnReaderBase *structReader,
            SelectiveColumnReader *fieldReader,
            uint64_t version)
            : structReader_(structReader),
              fieldReader_(fieldReader),
              version_(version) {
        }

    private:
        void loadInternal(
            RowSet rows,
            ValueHook *hook,
            vector_size_t resultSize,
            VectorPtr *result) override;

        SelectiveStructColumnReaderBase *const structReader_;
        SelectiveColumnReader *const fieldReader_;
        // This is checked against the version of 'structReader' on load. If
        // these differ, 'structReader' has been advanced since the creation
        // of 'this' and 'this' is no longer loadable.
        const uint64_t version_;
    };

    class DeltaUpdateColumnLoader : public VectorLoader {
    public:
        DeltaUpdateColumnLoader(
            SelectiveStructColumnReaderBase *structReader,
            SelectiveColumnReader *fieldReader,
            uint64_t version)
            : structReader_(structReader),
              fieldReader_(fieldReader),
              version_(version) {
        }

    private:
        void loadInternal(
            RowSet rows,
            ValueHook *hook,
            vector_size_t resultSize,
            VectorPtr *result) override;

        SelectiveStructColumnReaderBase *const structReader_;
        SelectiveColumnReader *const fieldReader_;
        const uint64_t version_;
    };
} // namespace kumo::pollux::dwio::common
